package day40.edu;

import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.Constructor;
import java.util.Properties;

public class FruitTest {
    @Test
    public void test1() throws Exception
    {
        // read the information of txt, receive the name of class
        Properties pros = new Properties();
        File file = new File("src/config.properties");


        FileInputStream fis = new FileInputStream(file);

        pros.load(fis);

        String fruitName = pros.getProperty("fruitName");

        // through the reflection, create the instance of class name
        Class clazz = Class.forName(fruitName);
        Constructor con = clazz.getDeclaredConstructor();
        con.setAccessible(true);

        Fruit fruit = (Fruit)con.newInstance();

        // through the object of juicer to call the run()
        Juicer juicer = new Juicer();
        juicer.run(fruit);

    }
}
